// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#ifndef _STDAFX_H_
#define _STDAFX_H_

#include <dlcom/cominc.h>

#include "sqlite3.h"

struct sqlite3_sentry {
    static void* default_value() { return 0; }
    template <class _Ptr> static bool equal_to(_Ptr l, _Ptr r) { return l == r; }
    template <class _Ptr> static void destroy(_Ptr p)
    {
        if (p != NULL) {
            sqlite3_finalize(p);
            p = NULL;
        }
    }
};

typedef SafePtr<sqlite3_stmt*, sqlite3_sentry> StmtPtr;

static inline sqlite3_stmt* compile(sqlite3* db, const char* szSQL)
{
    rc_error(db != NULL, NULL);
    const char* szTail = 0;
    sqlite3_stmt* pVM;

    int nRet = sqlite3_prepare_v2(db, szSQL, -1, &pVM, &szTail);
    const char* szError = sqlite3_errmsg(db);
    rc_error(nRet == SQLITE_OK, NULL);

    return pVM;
}

#endif
